<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8" />
		<title>4.列表过滤_computed</title>
		<!-- 引入Vue -->
		<script type="text/javascript" src="../js/vue.js"></script>
	</head>
	<body>
		<!-- 准备好一个容器-->
		<div id="demo">
			<h2>人员列表</h2>
			<input v-model="keyword" type="text" placeholder="输入姓名" >
			<ul>
				<li v-for="p in fltPersons" :key="p.id">
					{{p.name}} - {{p.age}} - {{p.sex}}
				</li>
			</ul>
		</div>

		<script type="text/javascript">
			//阻止 vue 在启动时生成生产提示。
			Vue.config.productionTip = false

			new Vue({
				el:'#demo',
				data:{
					keyword:'',
					persons:[
						{id:'yt7657wte',name:'马冬梅',sex:'女',age:19},
						{id:'0ijdsa9u9',name:'周冬雨',sex:'女',age:20},
						{id:'popoi009d',name:'周杰伦',sex:'男',age:21},
						{id:'gtryutjty',name:'温兆伦',sex:'男',age:22}
					]
				},
				computed: {
					fltPersons(){
						return this.persons.filter( p => p.name.indexOf(this.keyword) !== -1 )
					}
				}
			})
			
		</script>
	</body>
</html>